package DesignPattern.abstractFactory;

/**
 * @Author self
 * @Date 2025/7/13 14:47
 * @Describe
 */
public class Client {
    private Button button;
    private ScrollBar scrollBar;

    // 构造器注入工厂
    public Client(GUIFactory factory) {
        this.button = factory.createButton();
        this.scrollBar = factory.createScrollBar();
    }

    public void renderUI() {
        button.render();
        scrollBar.render();
    }

    public static void main(String[] args) {
        // 根据系统类型选择工厂
        String osType = "mac"; // 可改为 "windows"

        GUIFactory factory;
        if ("windows".equalsIgnoreCase(osType)) {
            factory = new WindowsFactory();
        } else if ("mac".equalsIgnoreCase(osType)) {
            factory = new MacFactory();
        } else {
            throw new IllegalArgumentException("Unsupported OS type.");
        }

        // 创建并渲染 UI 组件
        Client client = new Client(factory);
        client.renderUI();
    }
}
